#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define PII pair<int, int>
#define double long double
const int N = 5e5 + 10;
const int M = 64;
const int mod = 998244353;

void IOS(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

int d[N], c[N], b[N], ans[N];

void init(){
    d[0] = 1;
    for(int i = 1; i <= 5e5; i++){
        d[i] = i * d[i - 1] % mod;
        c[i] = (i * c[i - 1] + d[i - 1]) % mod;
        b[i] = (i * b[i - 1] + 2 * c[i - 1] + d[i - 1]) % mod;
        ans[i] = (i * ans[i - 1] + 3 * b[i - 1] + 3 * c[i - 1] + d[i - 1]) % mod;
    }
}

int n;

void solve(){
    cin >> n;
    cout << ans[n] << endl;
}

signed main(){
    IOS();
    init();
    int T = 1;
    cin >> T;
    while(T--){
        solve();
    }
    return 0;
}

